# -*- coding: utf-8 -*-\
# biblioteka do wyrazen regularnych
import re
#from lxml import etree


class Character(object): #klasa abstrakcyjna, tylko do dziedziczenia

	#### ####
	# Const
	### ###
	STR = 0; DEX = 1; CON = 2; INT = 3; WIS = 4; MAX_STAT = 5

	# wyrazenie regularne do sprawdzania imienia
	validName = ur"^([A-ZĄĘŚĆŻŹŁÓĆŃ]{1})[a-ząęśćżźłóćń]{1,11}$" 
	
	CurrentHealth = 0
	MaxHealth = 100
	
	
	# STATYSTYKI
	stats = [0, 0, 0, 0, 0] # uzyj stalych do indeksowania statystyk

	# GET
	def getName(self):
		return self.Name
	
	
	def validateName(self, inputName):
		return re.match(self.validName, inputName)
		
	def getCurrentHealth(self):
		return self.CurrentHealth
		
	def getMaxHealth(self):
		return self.MaxHealth
		
	def getStatistics(self, index):
		if index < 0 or index > MAX_STAT :
			return -1
			
		return self.stats[index]
	
	def isPlayer(self):
		return False
	
	def isMonster(self):
		return False
	
	def isNPC(self):
		return False
		
	
	
	# SET
	def setName(self, inputName):
		validation = self.validateName(inputName)
		
		if validation:
			self.Name = inputName
		
		return validation
	
		
	def changeCurrentHealth(self, delta):
		tmp = self.CurrentHealth + delta
		if tmp <= 0:
			tmp = 0
			# die
			
		if tmp > self.getMaxHealth():
			return False
			
		self.CurrentHealth = tmp
		return True
		
	def setMaxHealth(self, value):
		if value < 0:
			return False
			
		self.MaxHealth = value
		return True
		
	def setStatistic(self, value, index):
		if index < 0 or index > self.MAX_STAT or value < 0 or value > 500 :
			return False
			
		self.stats[index] = value
		return True



class Player(Character):
	
	#### ####
	# Const
	### ### ###
	# look
	HEIGHT = 0; BUILD = 1; FACE = 2; FACEATT = 3; RACEATT = 4; HAIR1 = 5; HAIR2 = 6; HAIR3 = 7; MAX_LOOK = 8
	
	### ### ###

	Place = u"Dunno"
	Karma = 0
	
	Exp = 0
	Lvl = 1
	
	# WYGLAD
	look = {} # uzyj stalych do indeksowania wygladu
		
	def die(self):
		del(self)
	
	# GET
	def isPlayer(self):
		return True
	
	def calculateHealth(self):
		health = ((self.getStatistics(self.CON)*3)+self.getStatistics(self.STR))/1.5
		health = math.floor(health)
		health = int(health)
		return health
	
	def getPlace(self):
		return self.PlayerPlace
		
	def getKarma(self):
		return self.Karma
	
	def getExp(self):
		return self.Exp
		
	def getLvl(self):
		return self.Lvl
	

	# SET
	def setExp(self, exp):
		if exp < 0 :
			return False
			
		self.Exp = exp
		return True
		
	def addExp(self, exp):
		return False # funkcja do napisania, poza tym zaleznosc exp od lvl
		
	def changeCurrentHealth(self, delta):
		if  + delta == 0 :
			self.die()
			
		else :
			# uzycie metody z klasy rodzica
			return super(Player, self).changeCurrentHealth(delta)
	
	
	def __init__(self, name, raceId, raceName, statsTable, height, build, face, faceatt, raceatt, hair1, hair2, hair3, place, karma, exp, lvl): #konstruktor
		self.setName(name)
		
		self.RaceId = raceId
		self.RaceName = raceName
		
		index = 0
		while index < self.MAX_STAT:
			self.setStatistic(statsTable[index], index)
			index += 1
			# rzucanie wyjatkow dopisz
			
		del(index)
		
		
		self.look[self.HEIGHT] = height
		self.look[self.BUILD] = build
		self.look[self.FACE] = face
		self.look[self.FACEATT] = faceatt
		self.look[self.RACEATT] = raceatt
		self.look[self.HAIR1] = hair1
		self.look[self.HAIR2] = hair2
		self.look[self.HAIR3] = hair3
		
		self.Place = place
		self.Karma = karma
		
		self.setExp(exp)
		self.Lvl = lvl
		
		
	
print 1
# fragment do testow
x = Player(u"Kronos", 1, u"Człowiek", [100, 100, 100, 100, 100], u"height", u"build", u"face", u"faceatt", u"raceatt", u"hair1", u"hair2", u"hair3", u"place", u"karma", 666, 6)

print 2
boolTest = x.setName(u"")

if boolTest:
	print u"Działa!"
else:
	print u"Nie działa"
	
print x.getName()

raw_input()


